import cv2
import numpy as np

if __name__ == '__main__':
    # 1. 图片输入
    path = 'work3.jpg'
    image_np = cv2.imread(path)

    # y_min = (11, 43, 46)
    # y_max = (77, 255, 255)
    #
    # s_min = (130, 20, 60)
    # s_max = (155, 40, 90)
    # image_mask1 = cv2.inRange(image_np, y_min, y_max)
    # image_mask2 = cv2.inRange(image_np, s_min, s_max)
    # image_mask = cv2.bitwise_or(image_mask1, image_mask2)
    # image_np2 = cv2.bitwise_and(image_np, image_np, image_mask)

    # x_min_l, x_max_l = 420, 670
    # y_min_l, y_max_l = 490, 1400
    # line_width = 2
    # cv2.rectangle(image_np, (x_min_l, y_min_l), (x_max_l, y_max_l), (0, 0, 255), line_width)
    #
    # x_min_l, x_max_l = 146, 420
    # y_min_l, y_max_l = 1122, 1450
    # line_width = 2
    # cv2.rectangle(image_np, (x_min_l, y_min_l), (x_max_l, y_max_l), (0, 0, 255), line_width)
    # image_np_gray = cv2.cvtColor(image_np, cv2.COLOR_BGR2GRAY)
    # ret, image_thresh = cv2.threshold(image_np_gray,  127, 255, cv2.THRESH_OTSU + cv2.THRESH_BINARY)


    no_noise_image1 = cv2.blur(image_np,  (11, 11))
    no_noise_image2 = cv2.bilateralFilter(image_np, 5, 80, 80)

    no_noise_image1[490: 1400, 420:670] = no_noise_image2[490: 1400, 420:670]
    no_noise_image1[1122: 1450, 146:420] = no_noise_image2[1122: 1450, 146:420]




    cv2.imshow('', no_noise_image1)
    cv2.imwrite('zuoye3.jpg', no_noise_image1)
    cv2.waitKey(0)

